Repository navigation
feat: add an onFeatureFlags listener you can unsubscribe - #670
turnipdabeets wants to merge 21 commits into
Conversation
There was a problem hiding this comment.
PostHog Review · Standard · reviewed 34d79f4: 2 Should fix.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
posthog-flutter Compliance ReportDate: 2026-11-02T23:53:31.489315+00:00 ✅ All Tests Passed!47/47 tests passed Capture Tests✅ 30/30 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
5a85f1b to
2f7955e
Compare
de3a190 to
0a7ab2a
Compare
2f7955e to
a194366
Compare
dustinbyrne
left a comment
There was a problem hiding this comment.
The subscription API and ordinary delivery/replay paths look sound. Two dispatch-boundary cases remain: a config callback can restore an invalidated snapshot after reset/close, and a synchronous config-callback exception prevents runtime subscribers from receiving the load. Both reproduce through the public Dart API and IO channel harness.
AI-assisted review.
dustinbyrne
left a comment
There was a problem hiding this comment.
The previous web-loader, stale-native-notification and synchronous-replay findings are resolved in the focused regressions. Two runtime subscription routes remain incomplete: native auto-init does not activate the bridge when subscription is the first Dart operation, and Android manual reloads update neither subscribers nor their replay snapshot. Both reproduce independently; native 4.0 build availability remains a separate prerequisite.
AI-assisted review.
- Require posthog-ios 4.x. - Adapt to the reloadFeatureFlags(_:) callback that now passes a PostHogFeatureFlagsLoaded (PostHog/posthog-ios#913). - Note the payload decoding changes from PostHog/posthog-ios#903. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PostHog/posthog-ios#905 removes the legacy version/build properties from lifecycle events in 4.0, so Flutter iOS and macOS apps stop sending them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…listener posthog-ios 4.0 removes the didReceiveFeatureFlags notification.
* chore!: adopt posthog-android 4.0 * chore!: pass the loaded flags to onFeatureFlags and reloadFeatureFlags (#664) * chore!: pass the loaded flags to onFeatureFlags and reloadFeatureFlags onFeatureFlags and reloadFeatureFlags now carry a PostHogFeatureFlagsLoaded with the enabled flags, their values and whether loading failed, matching posthog-ios 4.0 and posthog-android 4.0. On web, reloadFeatureFlags completes right away with the flags loaded so far, because posthog-js doesn't report when a reload finishes. * fix: complete the web reloadFeatureFlags with the reloaded flags Wait for the next posthog-js onFeatureFlags call instead of returning the flags already loaded, so a failed reload reports errorsLoading. Complete right away when flags are disabled, and after twice the flags request timeout when posthog-js skips the request without calling back. * chore: use PostHogFeatureFlagsCallback from posthog-android 4.0 * chore: fix ktlint function-signature * fix: await posthog-js reloadFeatureFlagsAsync on web The next onFeatureFlags callback can carry a response from a request already in flight, so reloadFeatureFlags() could complete with flags from before the reload. posthog-js 1.438.2+ settles reloadFeatureFlagsAsync() after this reload's own request; use it when present and keep the callback path for older posthog-js. * docs: pass the loaded flags in the setup example * docs: drop best-effort web note from the person and group property methods * fix(web): wait for posthog-js flags retries before reporting a reload failure posthog-js retries a timed-out /flags request once by default, 500 ms later, inside the same reload. The older-JS deadline of twice the request timeout reported cached flags with errorsLoading set before a successful retry landed. * docs: note where onFeatureFlags and errorsLoading differ on Android and web * docs: describe the older posthog-js reload timeout as the full retry budget Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…s into one changeset Co-Authored-By: Claude Opus 5.5 <[email protected]>
fd88c7e to
7eebbca
Compare
…FeatureFlags, update API snapshot
… callback A config callback that threw kept listeners from getting the load, and a reset() or close() it started was undone when the load was cached after it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oader A registration whose unsubscribe isn't stored yet (close() during the synchronous replay) or never arrives (the loader snippet's stub) now goes inert once setup() or close() runs again. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dart bumps a generation when reset() or close() clears the listener registry and sends it with setup, reset and close. Android and iOS tag each onFeatureFlags notification with the generation they had when it fired, and Dart drops ones from an earlier generation, so the previous user's flags can't repopulate the replay cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With native auto-init, Posthog().onFeatureFlags() can be the app's only Dart SDK call, and nothing created the platform that installs the channel handler, so native loads never reached the listener. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…teners posthog-android passes a manual reload only to its completion, so no onFeatureFlagsCallback arrives and listeners missed the load while new ones replayed the older snapshot. A reload that finishes after a reset or close is still dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
26f2755 to
4d81d9e
Compare
posthog-android 4.0 drops RRStyle and the wireframe tree fields from the internal RRWireframe; screenshot frames don't need a style. Co-authored-by: Claude Opus 5.5 <[email protected]>
dustinbyrne
left a comment
There was a problem hiding this comment.
AI-assisted review. The earlier findings are resolved. One web reset/replay regression remains when reset waits behind async beforeSend; the inline comment includes the reproduction and controls.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… phase3/670 # Conflicts: # api/posthog_flutter.api.json # posthog_flutter/android/src/main/kotlin/com/posthog/flutter/PosthogFlutterPlugin.kt # posthog_flutter/darwin/posthog_flutter/Sources/posthog_flutter/PosthogFlutterPlugin.swift # posthog_flutter/lib/posthog_flutter_web.dart # posthog_flutter/lib/src/feature_flags_loaded.dart # posthog_flutter/lib/src/posthog.dart # posthog_flutter/lib/src/posthog_flutter_desktop.dart # posthog_flutter/lib/src/posthog_flutter_io.dart # posthog_flutter/lib/src/posthog_flutter_web_handler.dart # posthog_flutter/test/posthog_flutter_desktop_test.dart # posthog_flutter/test/posthog_flutter_io_test.dart
Posthog() creates PosthogFlutterIO, whose constructor set the channel handler and aborted without a binding. Retry the install instead, and fail native calls with a PlatformException so each caller's existing fallback applies.
|
cannot be tested e2e so moving to draft |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
💡 Motivation and Context
Brings Flutter to parity with posthog-ios 4.0 (
PostHogSDK.shared.onFeatureFlags(_:)) and posthog-android 4.0 (PostHog.onFeatureFlags(callback), PostHog/posthog-android#878). Until now Flutter only hadPostHogConfig.onFeatureFlags, which is fixed atsetup()and can't be removed.Same semantics as iOS and Android:
reloadFeatureFlags(),identify()/group()/reset()), witherrorsLoadingand the last known flags on failure.setup()and survivesclose()/setup().reset()andclose()drop the cached load, so a new listener never gets the previous user's flags.Implementation: a Dart-side registry (
FeatureFlagsListeners,@internal). Each platform delivers to it next to the existing config callback: method channel (iOS/Android/macOS), desktop client (Windows/Linux), and posthog-js on web. No native changes, since native already forwards every load.Web now registers its posthog-js
onFeatureFlagslistener even withoutconfig.onFeatureFlags, and unsubscribes it onclose()and before re-registering on repeatedsetup(). Before, everysetup()added another JS listener, so the config callback ran once persetup()call.A throwing listener is logged and doesn't stop the others. Web skips registration when the page's
posthogobject has noonFeatureFlags(test stubs), instead of throwing duringsetup().Stacked on #664 (needs
PostHogFeatureFlagsLoaded).💚 How did you test it?
test/feature_flags_listeners_test.dart: delivery until unsubscribe, one replay, replay skipped when a newer load wins, no replay after clear, unsubscribe during delivery, a throwing listener.posthog_flutter_io_test), desktop (posthog_flutter_desktop_test), web (posthog_flutter_web_setup_test, also covers repeated setup delivering once).posthog_test: no replay of flags loaded beforereset()/close().flutter analyzeclean,flutter testandflutter test --platform chrome test/posthog_flutter_web_setup_test.dartpass.🧪 How to test locally (for agents and reviewers)
CI's
build-androidandbuild-applejobs can't pass until posthog-ios and posthog-android 4.0 are released, because no 4.x version resolves yet. To test now, build against the nativefeat/v4-capture-v1branches. Don't commit these overrides.Android: check out
feat/v4-capture-v1of posthog-android, then:Add
mavenLocal()as the first repository inexample/android/build.gradle.kts. Use a new version for each republish, because Gradle can reuse a stale one.iOS/macOS: check out
feat/v4-capture-v1of posthog-ios and pointposthog_flutter/darwin/posthog_flutter/Package.swiftat it:Build: from
example/, with Swift Package Manager enabled (flutter config --enable-swift-package-manager), runflutter build apk --debugandflutter build ios --simulator --debug.Local server: set
config.hosttohttp://127.0.0.1:<port>.android:usesCleartextTraffic="true"to<application>and runadb reverse tcp:<port> tcp:<port>.NSAppTransportSecurity>NSAllowsArbitraryLoadsinRunner/Info.plist.{"hasFeatureFlags": true}from/array/<token>/config. Otherwise Android skips/flagsand reports empty flags.Run tests on a device with
flutter test integration_test/<file>.dart -d <device>.What to check on this PR: the test and server below cover the 11 listener scenarios. Run
python3 server.py server.log, save the test asexample/integration_test/flags_listener_e2e_test.dart, and run it. The server listens on port 8793.Results at
28bc2f0with posthog-ios18d94cbb8and posthog-androiddb4a11c4: 11/11 on an iOS simulator and 11/11 on an Android 14 emulator. Not yet run on physical devices or against a real PostHog project.server.py
flags_listener_e2e_test.dart
📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code wrote this while aligning the flags API across iOS 4, Android 4 and Flutter 6. Kept the listener in Dart instead of adding a native subscribe/unsubscribe channel method: native already pushes every load to Dart, so a Dart registry covers all five platforms with one implementation.
🤖 Generated with Claude Code